﻿using System;
using System.Linq;

namespace ZebraDatePickerDotNet.Dates
{
    public static class PersianNo
    {
        private static readonly char[] NumArr = new char[] { '٠', '۱', '٢', '٣', '۴', '۵', '۶', '٧', '٨', '٩' };
        //private static readonly char[] NumArrOriginal = new char[] { '0','1', '2', '3', '4', '5', '6', '7', '8', '9' };

        public static string ToPersianNo(this int input)
        {
            string ch = input.ToString();
            return ch.Aggregate("", (current, t) => current + NumArr[Convert.ToByte(t + "")]);
        }

        public static string ReplaceNo(this string input)
        {
            string result = input;
            if (!string.IsNullOrEmpty(input))
            {
                for (int i = 0; i < NumArr.Length; i++)
                {
                    result = result.Replace(i + "", NumArr[i] + "");
                }
            }
            return result;
        }

        public static VDate ToShamsi(this string input)
        {
            VDate result = null;
            VDate.TryParse(input, out result);

            return result;
        }

        public static VDate ToShamsi(this DateTime input)
        {
            return new VDate(input);
        }

        public static string ToShamsi(this DateTime input, string format)
        {
            return ToShamsi(input).ToString(format);
        }
    }
}
